# -*- coding: utf-8 -*-
"""part2: 生产者-消费者
生产者
"""

import sys
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('172.22.23.252'))

channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)  # 队列持久化

message = ''.join(sys.argv[1:]) or "Hello Word!"

channel.basic_publish(exchange='',
                      routing_key='task_queue',
                      body=message,
                      properties=pika.BasicProperties(
                          delivery_mode=2  # 消息持久化
                      ))
print("[x] Sent %s" % message)

connection.close()
